Skip to content

Conversation

@raul338
Copy link
Contributor

@raul338 raul338 commented Jul 22, 2015

For example the following code

<nav class="navbar navbar-default navbar-fixed-top">
    <div class="container-fluid">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar-collapse">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="/">Book Marketer</a>
        </div>
        <div class="collapse navbar-collapse" id="navbar-collapse">
<?php
echo $this->Html->navbarNav(
    [
        'Books' => [
            [
                'link',
                'Books',
                ['controller' => 'Books', 'action' => 'index'],
                '_options' => ['class' => $this->name == 'Books' ? 'active' : '', 'escape' => false]
            ],
            [
                'link',
                'Tags',
                ['controller' => 'Tags', 'action' => 'index'],
                '_options' => ['class' => $this->name == 'Tags' ? 'active' : '', 'escape' => false]
            ],
            '_options' => [
                'li' => ['class' => ($this->name == 'Books' || $this->name == 'Tags') ? 'active' : ''],
                'link' => ['escape' => false]
            ]
        ],
        $this->Html->tag('p', 'Signed as Mark Otto', ['class' => 'navbar-text'])
    ],
    ['escape' => false]
);
?>
        </div>
    </div>
</nav>

Will produce the next result
screenshot_20150722_004839
allowing to add atributes to the li item, the link and the dropdown.

Maybe it need's some testing and some code review. Tried to be as clean as posible

@Holt59
Copy link
Collaborator

Holt59 commented Jul 22, 2015

There were once a specific helper to generate navbar (see https://github.com/Holt59/cakephp-bootstrap3-helpers/blob/master/View/Helper/BootstrapNavbarHelper.php) with lots of feature and working a bit like the FormHelper (you call create, then beginMenu, endMenu etc. until compile and end). I never had the time (and the patience... ) to move it from cakephp 2.0 to cakephp 3.0.

I think navbar are a big deal but having everything in one function doesn't seem right for me, so I will try to upgrade the BootstrapNavbarHelper as soon as possible.

@raul338
Copy link
Contributor Author

raul338 commented Jul 22, 2015

:O Sorry, I never saw it. Maybe the code can be reused, because it doesn't
generate the whole navbar, just the "main menu" (almost same logic as
dropdown), no forms, no brand image, etc.
I'll going to see that cake2 navbar helper. Thanks to notice me.
El 22/07/2015 03:44, "Mikaël Capelle" notifications@github.com escribió:

There were once a specific helper to generate navbar (see
https://github.com/Holt59/cakephp-bootstrap3-helpers/blob/master/View/Helper/BootstrapNavbarHelper.php)
with lots of feature and working a bit like the FormHelper (you call
create, then beginMenu, endMenu etc. until compile and end). I never had
the time (and the patience... ) to move it from cakephp 2.0 to cakephp 3.0.

I think navbar are a big deal but having everything in one function
doesn't seem right for me, so I will try to upgrade the
BootstrapNavbarHelper as soon as possible.


Reply to this email directly or view it on GitHub
#40 (comment)
.

@Holt59
Copy link
Collaborator

Holt59 commented Jul 22, 2015

I just pushed a commit with a new BootstrapNavbarHelper. The standard functionalities should work fine, but it needs some more testing and tuning. Here is an example on how it works:

echo $this->Navbar->create('Mikael Capelle', array('fixed' => 'top', 'responsive' => 'false', 'inverse' => true)) ;
echo $this->Navbar->beginMenu () ;
    echo $this->Navbar->link('Link', '/', ['class' => 'active']) ;
    echo $this->Navbar->link('Blog', array('controller' => 'pages', 'action' => 'test')) ;
    echo $this->Navbar->beginMenu ('Dropdown') ;
        echo $this->Navbar->link ('Action');
        echo $this->Navbar->link ('Another action') ;
        echo $this->Navbar->link ('Something else here') ;
        echo $this->Navbar->divider () ;
        echo $this->Navbar->link ('Another action') ;
        echo $this->Navbar->divider () ;
        echo $this->Navbar->link ('Another action') ;
    echo $this->Navbar->endMenu () ;
echo $this->Navbar->endMenu () ;
echo $this->Navbar->searchForm () ;
echo $this->Navbar->text('Signed in as <a href="#" class="classtest">Holt59</a>, <a href="#">Log Out</a>');
echo $this->Navbar->link('Profile');
echo $this->Navbar->end() ; 

You can have a menu with submenu (the subsubmenus are not working yet), there are some custom stuff like the following ones:

  • If you call link outside of a menu, it will create a button instead of a link.
  • If you call the text method with some links inside, the navbar-link class will automatically be added to them

I will work on some feature to automatically add « active » class on menu when I have time.

Result of the above code:
image

@raul338
Copy link
Contributor Author

raul338 commented Jul 22, 2015

Cool! Thanks!!
It works and this way is better. However, you made a typo in line 76 (used fixed instead of _fixed)
I'll keep testing.

Also I don't think the auto "active" class is necesary, I think that belongs to the user (?)

@raul338 raul338 closed this Jul 22, 2015
@Holt59
Copy link
Collaborator

Holt59 commented Jul 22, 2015

Thanks for the typo, it's corrected. Concerning the active class, I don't really like having to specify it manually, I'd rather let the users disable this feature if they want (by setting autoActiveLink to false). I'll update the documentation as soon as possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants